<?php
/*
 * @@Copyright (C), 2021-2022: 恒盛时代
 * @Author: zhouzhou
 * @Date: 2021/12/3
 * @Description:通用设置
 */

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class ImUserCurrent extends BaseModel
{
    protected $table = 'im_user_current';
    public $fillable = ['user_id'];
    protected $hidden = ['created_at','updated_at'];

    /**
     * @desc 设置我的通用
     * @param array $input 传过来数组对象
     * @param int $userId 用户id
     * @return array|int[]
     * @author zhouzhou
     * @time 2021/12/3 14:58
     */
    public function setCurrent($input,  $userId)
    {
        $type = $input['type'];
        $value = $input['value'];
        $userCurrent = $this->where('user_id', $userId)->first();
        switch($type)
        {
            case ($type == 1):  // 外观默认1跟随系统，2浅色，3深色
                $userCurrent->outward = $value;
                break;
            case ($type == 2):  // '语言设置：默认1简体中文，2繁体中文香港，3繁体中文台湾，4英文，5日本语
                $userCurrent->language = $value;
                break;
            case ($type == 3):  // 内内容翻译为：默认1简体中文，2英文，3日语
                $userCurrent->content_render = $value;
                break;
            case ($type == 4):  // 翻译的显示效果：默认1显示原文译文，2仅仅显示译文
                $userCurrent->render_show = $value;
                break;
            case ($type == 5):  // 自动翻译：默认0不自动翻译，1打开自动翻译
                $userCurrent->auto_render = $value;
                break;
            case ($type == 6):  // 字体大小:默认1
                $userCurrent->font_number = $value;
                break;
            case ($type == 7):  // 聊天背景
                $userCurrent->img = $value;
                break;
            case ($type == 8):  // 听筒模式：默认0未打开，1打开
                $userCurrent->earpiece = $value;
                break;
            case ($type == 9):  // 语音自动转文字：默认0未打开，1打开
                $userCurrent->voice_word = $value;
                break;
            default :
                break;
        }

        if($userCurrent->save() == FALSE)
        {
            return ['code' => 1, 'msg' => '设置失败'];
        }

        return ['code' => 0, 'id' => $this->id, 'msg' => '设置成功'];
    }




}
